package com.spring.blog.controller;

import com.spring.blog.pojo.request.UserLoginRequest;
import com.spring.blog.pojo.response.GetUserInfoResponse;
import com.spring.blog.pojo.response.UserLoginResponse;
import com.spring.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserInfoController {
    //bean对象 小驼峰
    @Resource(name = "userServiceImpl")
    private UserService userService;
    @RequestMapping("/login")
    //@RequestBody 传的请求是json格式
    //@Valid 可以对对象进行参数校验
    public UserLoginResponse login(@Validated @RequestBody UserLoginRequest userLoginRequest){
        UserLoginResponse userLoginResponse=userService.login(userLoginRequest);
        return userLoginResponse;

    }
    @RequestMapping("/getUserInfo")
    public GetUserInfoResponse getUserInfo(@NotNull(message = "userId不可以为null") Integer userId){
        GetUserInfoResponse getUserInfoResponse=userService.getUserInfo(userId);
        return getUserInfoResponse;
    }
    @RequestMapping("/getAuthorInfo")
    public GetUserInfoResponse getAuthorInfo(@NotNull(message = "blogId不可以为null") Integer blogId){
        GetUserInfoResponse getUserInfoResponse=userService.getAuthorInfo(blogId);
        return getUserInfoResponse;
    }

}
